from django_filters.rest_framework import DjangoFilterBackend
import django_filters

from drfapp.models import BOOK,Hero



# 设置局部过滤    模糊查询


class BookFilter(django_filters.rest_framework.FilterSet):
    btitle = django_filters.CharFilter(field_name="btitle", lookup_expr="icontains")  # icontains 表示 包含（忽略大小写）

    class Meta:
        model = BOOK  # 关联的表
        fields = ['btitle']  # 过滤的字段


class HeroFilter(django_filters.rest_framework.FilterSet):
    hname=django_filters.CharFilter(field_name='hname',lookup_expr='icontains')

    class Meta:
        model=Hero
        fields=['hname']